/**
 * 
 */
package com.alstudio.view.image;

import android.graphics.Bitmap;

import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;

/**
 * @author alonso lee
 *
 */
public class ALRoundImageDisplayer implements BitmapDisplayer{
	
	protected final int cornerRadius;
	protected final int margin;

	public ALRoundImageDisplayer(int cornerRadiusPixels) {
		this(cornerRadiusPixels, 0);
	}

	public ALRoundImageDisplayer(int cornerRadiusPixels, int marginPixels) {
		this.cornerRadius = cornerRadiusPixels;
		this.margin = marginPixels;
	}

	@Override
	public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
		if (!(imageAware instanceof ImageViewAware)) {
			throw new IllegalArgumentException("ImageAware should wrap ImageView. ImageViewAware is expected.");
		}

		imageAware.setImageDrawable(new RoundedDrawable(bitmap).setCornerRadius(cornerRadius));
	}


}
